package day04;

/**
 * @author Jetwang
 * @version 1.0
 * @since 2023/3/15 19:00
 * 丑数
 */
public class Offer49Non {

    public static void main(String[] args) {
        System.out.println(nthUglyNumber(10));
    }

    public static int nthUglyNumber(int n) {
        int count = 0;
        int res = 0;
        while(count != n) {
            res++;
            if (isUglyNumber(res)) {
                count++;
            }
        }
        return res;
    }

    private static boolean isUglyNumber(int num) {
        while(num % 2 == 0) {
            num /= 2;
        }
        while(num % 3 == 0) {
            num /= 3;
        }
        while(num % 5 == 0) {
            num /= 5;
        }
        return num == 1;
    }
}
